<?php

class MyModule extends fvModule {

	function __construct () {
		$moduleName = strtolower(substr(__CLASS__, 0, -6));

		parent::__construct(fvSite::$fvConfig->get("modules.{$moduleName}.smarty.template"),
		fvSite::$fvConfig->get("modules.{$moduleName}.smarty.compile"),
		fvSite::$Layoult);
	}

	function showIndex($params) {
		$Customer = CustomerManager::getInstance()->getByPk(fvSite::$fvSession->getCustomer()->getPk());
		$Orders = OrderManager::getInstance()->getAll('customer_id='.$Customer->getPk());
		$this->__assign("LoggedUser", $Customer);
		$this->__assign('Orders', $Orders);
		$this->__assign('Products', ProductsManager::getInstance());
		$this->__assign('Success', fvSite::$fvSession->get('Success'));
		$this->__assign('curdate', date('Y-m-d',strtotime("today -7 days")));
		fvSite::$fvSession->set('Success', null);
		return $this->__display("my_index.tpl");
	}
	
	function showEdit($params) {
		$Customer = CustomerManager::getInstance()->getByPk(fvSite::$fvSession->getCustomer()->getPk());
		$this->__assign("LoggedUser", $Customer);
		$this->__assign('Success', fvSite::$fvSession->get('Success'));
		$this->__assign('Error', fvSite::$fvSession->get('Error'));
		fvSite::$fvSession->set('Success', null);
		fvSite::$fvSession->set('Error', null);
		return $this->__display("my_edit.tpl");
	}
	
	function showShoworder($params) {
		$Customer = CustomerManager::getInstance()->getByPk(fvSite::$fvSession->getCustomer()->getPk());
		$this->__assign("LoggedUser", $Customer);
		$id = fvRequest::getInstance()->getRequestParameter("id");
		$Order = OrderManager::getInstance()->getAll('id='.$id." and customer_id=".$Customer->getPk());
		$Products = array() ;
		foreach ($Order[0]->products as $k=>$v){
    		$Products[$k] = ProductsManager::getInstance()->getByPk($v["product_id"]);
    		$Products[$k]["count"] = $v["count"];
    	}
	    $this->__assign("Products", $Products);
		return $this->__display("my_showorder.tpl");
	}

}

?>
